-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs(start): createIsomorphicFn and envOnly #4806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
a675dae
to
9cab129
Compare
### Complete Implementation | ||
|
||
```tsx | ||
const getEnv = createIsomorphicFn() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make those snippets complete by adding the import from '@tanstack/solid-start'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applies to all examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -0,0 +1,3 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once we have settled on the text for react, please duplicate and change the imports to point to solid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hokkyss see the docs in docs/router/framework/solid/devtools.md
which have a syntax for performing text replacements on the ref
doc. So you shouldn't need to duplicate the entire document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. Updated guys. Thank you
@@ -98,7 +98,7 @@ response?: 'data' | 'full' | 'raw' | |||
- From other server functions | |||
|
|||
> [!WARNING] | |||
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we can now call server functions from API routes. please check and and if true, this text can be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schiller-manuel is right. API routes as a whole became the new "Server Routes" which support calling Server Function.
This warning can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, this is deleted
we also got those docs recently: b402bbc maybe just improve those where needed? |
@@ -98,7 +98,7 @@ response?: 'data' | 'full' | 'raw' | |||
- From other server functions | |||
|
|||
> [!WARNING] | |||
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schiller-manuel is right. API routes as a whole became the new "Server Routes" which support calling Server Function.
This warning can be removed.
@@ -0,0 +1,3 @@ | |||
--- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hokkyss see the docs in docs/router/framework/solid/devtools.md
which have a syntax for performing text replacements on the ref
doc. So you shouldn't need to duplicate the entire document.
Use `createIsomorphicFn()` to define functions that behave differently depending on whether they are called on the client or the server. This is useful for safely sharing logic across environments while delegating environment-specific behavior to appropriate handlers. | ||
|
||
> [!WARNING] | ||
> Unimplemented function results in a no-op function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of a warning, this could be a small heading like "What is a no-op?", that'd show the user the type of a no-op.
Perhaps something like this:
type NoOpFunction = () => undefined // add a comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
I have added an explanation at the end of createIsomorphicFn
as h4
docs/start/config.json
Outdated
@@ -122,6 +126,10 @@ | |||
"label": "Static Server Functions", | |||
"to": "framework/solid/static-server-functions" | |||
}, | |||
{ | |||
"label": "Environment Functions", | |||
"to": "framework/react/environment-functions" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to": "framework/react/environment-functions" | |
"to": "framework/solid/environment-functions" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! Updated.
WalkthroughAdds “Environment Functions” docs for React and Solid, updates navigation to include them, and removes a warning plus two bullets from the React server functions doc. Solid’s page references the React doc via front matter replace rules. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (11)
docs/start/config.json (1)
44-47
: Optional: Consider renaming “Environment Functions” to “Isomorphic Utilities”Since the PR description questions the naming, “Isomorphic Utilities” (or “Environment-aware Utilities”) may better convey the intent without implying only functions. If you prefer this, we should update both the page titles and these nav labels together.
Also applies to: 129-132
docs/start/framework/react/environment-functions.md (9)
10-15
: Grammar: “Start provides”Subject-verb agreement and light copy tweaks.
-Start provide three core environment functions: +Start provides three core environment functions:
45-48
: Grammar: “a no-op” and punctuationClarify the client behavior phrasing.
-// ℹ️ On the **client**, it is no-op (returns `undefined`) +// ℹ️ On the **client**, it is a no-op (returns `undefined`).
59-62
: Grammar: “a no-op” and punctuationSame tweak for the server-side note.
-// ℹ️ On the **server**, it is no-op (returns `undefined`) +// ℹ️ On the **server**, it is a no-op (returns `undefined`).
73-75
: Grammar: “a no-op” and punctuationApply the same phrasing/punctuation for consistency.
-// ℹ️ On both **client** and **server**, it is no-op (returns `undefined`) +// ℹ️ On both **client** and **server**, it is a no-op (returns `undefined`).
88-91
: Fix heading: backticks and casingCurrent “##
env
Only Functions” renders oddly. Prefer plain language.-## `env`Only Functions +## Environment-only Functions
117-123
: Tree-shaking section: wording and clarityMinor grammar improvements and clearer phrasing.
-Environment functions are tree-shaken based on the environment for each bundle produced. +Environment functions are tree-shaken per environment for each produced bundle. -Functions created using `createIsomorphicFn()` are tree-shaken. All codes inside `.client()` are not included in server bundle, and vice-versa. +Functions created using `createIsomorphicFn()` are tree-shaken. All code inside `.client()` is excluded from the server bundle, and vice versa. -On the server, implementation of `clientOnly` functions are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions on the client. +In the server bundle, `clientOnly` implementations are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions in the client bundle.
79-85
: TS typing for no-op exampleIf we want to be explicit for TypeScript users, “void” is the idiomatic return type for a no-op (you can still note that it evaluates to
undefined
at runtime).-// basic no-op implementation -function noop() {} +// basic no-op implementation (TypeScript) +const noop: () => void = () => {}
99-112
: Avoid locking docs to exact error message stringsThe quoted error texts might diverge from implementation over time. Suggest describing the behavior generically or quoting less rigidly (e.g., “throws an error on the client/server”).
Would you like me to replace the exact strings with a generic description, or verify the current runtime messages in the codebase to keep them accurate?
1-4
: Optional: Page title namingIf you decide to rename the nav label (e.g., to “Isomorphic Utilities”), mirror it here for consistency.
-title: Environment Functions +title: Isomorphic Utilitiesdocs/start/framework/solid/environment-functions.md (1)
1-4
: Consider adding a capitalized replacement and validate scopeIf the source doc contains “React” (capitalized) or other proper nouns, also add a case-sensitive replacement to ensure titles and prose read naturally for Solid. Example:
--- ref: docs/start/framework/react/environment-functions.md -replace: { 'react': 'solid' } +replace: + { + 'react': 'solid', + 'React': 'Solid' + } ---Also, confirm the replacement mechanism applies to code blocks as intended (e.g., it should convert
@tanstack/react-start
to@tanstack/solid-start
without affecting unrelated identifiers).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (4)
docs/start/config.json
(2 hunks)docs/start/framework/react/environment-functions.md
(1 hunks)docs/start/framework/react/server-functions.md
(0 hunks)docs/start/framework/solid/environment-functions.md
(1 hunks)
💤 Files with no reviewable changes (1)
- docs/start/framework/react/server-functions.md
🧰 Additional context used
🪛 LanguageTool
docs/start/framework/solid/environment-functions.md
[grammar] ~1-~1: Hier könnte ein Fehler sein.
Context: --- ref: docs/start/framework/react/environment-functions.md replace: { 'react': 'solid' } ---
(QB_NEW_DE)
docs/start/framework/react/environment-functions.md
[grammar] ~12-~12: There might be a mistake here.
Context: ... to both client and server environments. - serverOnly
: Ensures a function can only run on the...
(QB_NEW_EN)
[grammar] ~114-~114: There might be a mistake here.
Context: ...be called on the client!" ``` > [!NOTE] > These functions are useful for API acc...
(QB_NEW_EN)
[grammar] ~121-~121: There might be a mistake here.
Context: ...des inside .client()
are not included in server bundle, and vice-versa. On the ...
(QB_NEW_EN)
🔇 Additional comments (3)
docs/start/config.json (2)
44-47
: Nav entry for React looks goodThe route slug matches the new doc file and placement (after Static Server Functions) is consistent.
129-132
: Nav entry for Solid looks goodSlug matches the Solid doc and mirrors the React placement.
docs/start/framework/solid/environment-functions.md (1)
1-4
: Front matter approach looks goodUsing ref + replace keeps the content DRY across frameworks.
Add docs for
createIsomorphicFn
,serverOnly
, andclientOnly
.I am not quite sure whether "environment functions" is a good name though
Summary by CodeRabbit